package cn.tedu.hotel.controller;

import cn.tedu.hotel.pojo.dto.PictureAddNewDTO;
import cn.tedu.hotel.pojo.vo.PictureListItemVO;
import cn.tedu.hotel.service.IPictureService;
import cn.tedu.hotel.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理图片相关数据的控制器类
 */
@Api(tags = "05. 图片管理模块")
@Slf4j
@RestController
@RequestMapping("/pictures")
public class PictureController {

    @Autowired
    private IPictureService pictureService;

    public PictureController() {
        log.info("创建控制器：PictureController");
    }

    @ApiOperation("添加图片")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(PictureAddNewDTO pictureAddNewDTO) {
        log.debug("开始处理【添加图片】的请求：{}", pictureAddNewDTO);
        pictureService.addNew(pictureAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除图片")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除图片】的请求：id={}", id);
        pictureService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询图片列表")
    @ApiOperationSupport(order = 300)
    @GetMapping("")
    public JsonResult<List<PictureListItemVO>> listPicture(){
        log.debug("开始处理【查询图片列表】的请求");
        List<PictureListItemVO> pictureListItemVOS = pictureService.listPicture();
        return JsonResult.ok(pictureListItemVOS);
    }

    @ApiOperation("设置启用为封面")
    @ApiOperationSupport(order = 401)
    @PostMapping("/{id:[0-9]+}/is-cover")
    public JsonResult<Void> setIsCover(@PathVariable Long id){
        log.debug("开始处理【将图片设置为封面】的请求，id={}",id);
        pictureService.setIsCover(id);
        return JsonResult.ok();

    }

    @ApiOperation("设置为不启用封面")
    @ApiOperationSupport(order = 402)
    @PostMapping("/{id:[0-9]+}/not-cover")
    public JsonResult<Void> setNotCover(@PathVariable Long id){
        log.debug("开始处理【将图片设置为不是封面】的请求，id={}",id);
        pictureService.setNotCover(id);
        return JsonResult.ok();

    }

}
